import 'package:flutter/material.dart';

class testPersonDetail extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: UserProfilePage(),
    );
  }
}

class UserProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('个人详情'),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            // handle back button press
          },
        ),
        actions: [
          IconButton(
            icon: Icon(Icons.more_vert),
            onPressed: () {
              // handle more button press
            },
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            UserInfo(),
            SizedBox(height: 12, child: Container(color: Color(0xFFF5F6FA))),
            ContactInfo(),
            //用父布局中所有可用的剩余空间，将 ActionButtons 固定在底部
            Spacer(),
            ActionButtons(),
          ],
        ),
      ),
    );
  }
}

class UserInfo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        CircleAvatar(
          radius: 40,
          backgroundImage: NetworkImage(
              'https://example.com/user_profile_image.jpg'), // Replace with the actual image URL
        ),
        SizedBox(width: 16),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              '丁胜亚',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            Text(
              '副主任',
              style: TextStyle(fontSize: 16, color: Colors.grey),
            ),
          ],
        ),
      ],
    );
  }
}

class ContactInfo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ContactInfoRow(
          label: '行政区划',
          value: '辽宁省',
        ),
        ContactInfoRow(
          label: '单位',
          value: '省大数据管理中心',
        ),
        ContactInfoRow(
          label: '部门',
          value:
          '部门是否显示全路径根据后台配置控制，默认仅显示当前部门\n省大数据管理中心-网络技术部\n省大数据管理中心-政务数据管理中心',
        ),
        ContactInfoRow(
          label: '办公电话',
          value: '010-78127893-8865',
        ),
        SizedBox(height: 12, child: Container(color: Color(0xFFF5F6FA))),
        ContactInfoRow(
          label: '移动电话',
          value: '点击查看',
          isLink: true,
        ),
        ContactInfoRow(
          label: '电子邮箱',
          value: 'dingshy@gov.cn',
        ),
      ],
    );
  }
}

class ContactInfoRow extends StatelessWidget {
  final String label;
  final String value;
  final bool isLink;

  ContactInfoRow({required this.label, required this.value, this.isLink = false});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 80,
            child: Text(
              label,
              style: TextStyle(fontSize: 17),
            ),
          ),
          Expanded(
            child: Align(
              alignment: Alignment.centerRight,
              child: isLink
                  ? GestureDetector(
                onTap: () {
                  // handle link tap
                },
                child: Text(
                  value,
                  style: TextStyle(color: Colors.blue, fontSize: 15),
                ),
              )
                  : Column(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: value
                    .split('\n')
                    .map((line) => Padding(
                  padding: const EdgeInsets.symmetric(vertical: 2.0),
                  child: Text(
                    line,
                    textAlign: TextAlign.right,
                    style: TextStyle(
                      color: line.contains('是否显示全路径') ||
                          line.contains('网络技术部') ||
                          line.contains('政务数据管理中心')
                          ? Colors.blue
                          : Colors.grey,
                      fontSize: 15,
                    ),
                  ),
                ))
                    .toList(),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class ActionButtons extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        ActionButton(
          icon: Icons.phone,
          label: '打电话',
          onPressed: () {
            // handle phone call action
          },
        ),
        ActionButton(
          icon: Icons.message,
          label: '发短信',
          onPressed: () {
            // handle send message action
          },
        ),
        ActionButton(
          icon: Icons.chat,
          label: '发消息',
          onPressed: () {
            // handle send chat action
          },
        ),
      ],
    );
  }
}

class ActionButton extends StatelessWidget {
  final IconData icon;
  final String label;
  final VoidCallback onPressed;

  ActionButton({required this.icon, required this.label, required this.onPressed});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        IconButton(
          icon: Icon(icon, size: 32),
          onPressed: onPressed,
        ),
        Text(label),
      ],
    );
  }
}
